import requests

from basic_基础信息.basic_传输数据 import token_merchant
from loguru import logger

from runner_运行程序 import ENV


def request_hook(response,*args,**kwargs):
    logger.info(f"接口响应信息为:{response.text}")

class BasicRequests:
    def __init__(self):
        self._session = requests.Session()
        self._session.hooks['response'].append(request_hook)



class MerchantRequests(BasicRequests):
    def __init__(self):
        super().__init__()
        self._session.headers.update({'authori-zation':token_merchant,'content-type':'application/json'})
    def get(self,api_name,url,params=None):
        url=f'{ENV.host_merchant}{url}'
        logger.info(f"接口{api_name}请求信息为:GET {url} params:{params}")
        response = self._session.get(url=url,params=params)
        return response.json()
    def post(self,api_name,url,json=None):
        url=f'{ENV.host_merchant}{url}'
        logger.info(f"接口{api_name}请求信息为:POST {url} json:{json}")
        response = self._session.post(url=url,json=json)
        return response.json()


